<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@ include file="/common/common-css.v2.jsp" %>
    <style>
        #jquery-table td {
            cursor: pointer !important;
            word-break: break-all;
            word-wrap: break-word;
        }

        .load_bg {
            background: #000;
            opacity: 0.1;
            left: 0;
            top: 0;
            position: fixed;
            height: 100%;
            width: 100%;
            overflow: hidden;
            z-index: 10000;
        }

        .load_img {
            left: 50%;
            top: 180px;
            position: fixed;
            height: 50px;
            overflow: hidden;
            z-index: 20000;
        }
    </style>
</head>
<body class="no-skin">
<div class="load_bg" style="display:none;"></div>
<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display:none"/>
<div class="page-content">
    <form id="queryForm" method="post" >
        <div class="page-content-area">
            <div class="row">
                <div class="col-sm-12">
                    <div class="widget-box" style="border:0 solid #ccc; border-top:none;border-bottom:none;">
                        <div class="widget-header widget-header-blue widget-header-flat">
                            <h4 class="widget-title">选择条件进行查询</h4>

                            <div class="widget-toolbar">
                                <a href="#" data-action="collapse">
                                    <i class="ace-icon fa fa-chevron-up"></i>
                                </a>
                            </div>
                        </div>

                        <div class="widget-body">
                            <div class="widget-main clearfix">

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" style="text-align:right"
                                           for="startDate">开始时间:</label>
                                    <div class="col-sm-8">
                                        <div class="input-daterange input-group">
                                            <input type="text" class="date-picker form-control"
                                                   data-date-format="yyyy-mm-dd" style="padding-left:0"
                                                   name="startDate" id="startDate" placeholder="请选择查询开始时间">
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" style="text-align:right"
                                           for="endDate">结束时间:</label>
                                    <div class="col-sm-8">
                                        <div class="input-daterange input-group">
                                            <input type="text" class="date-picker form-control"
                                                   data-date-format="yyyy-mm-dd" style="padding-left:0"
                                                   name="endDate" id="endDate" placeholder="请选择查询结束时间">
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" for="platform"
                                           style="text-align:right;">平台:</label>
                                    <div class="col-sm-8">
                                        <select class="form-control" name="platform" id="platform">
                                            <option value="-1" selected>全部</option>
                                            <option value="0">iOS</option>
                                            <option value="1">Android</option>
                                            <option value="2">其它</option>
                                        </select>
                                    </div>
                                </div>


                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" for="codeChannel"
                                           style="text-align:right;">二维码渠道:</label>
                                    <div class="col-sm-8">
                                    
                                     <s:select id="codeChannel" name="codeChannel" list="%{codeChannels}" cssClass="form-control" headerKey="" headerValue="--全部渠道--"/>
											
                                    </div>
                                </div>

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" for="type"
                                           style="text-align:right;">派券类型:</label>
                                    <div class="col-sm-8">
                                        <select class="form-control" name="type" id="type">
                                            <option value="-1" selected>全部</option>
                                            <option value="0">实物卡</option>
                                            <option value="1">不干胶</option>
                                        </select>
                                    </div>
                                </div>
                                
                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" for="channel"
                                           style="text-align:right;">优惠码渠道:</label>
                                    <div class="col-sm-8">
                                    
                                   		  <s:select id="channel" name="channel" list="%{allChannels}" cssClass="form-control" headerKey="" headerValue="--全部渠道--"/>
											
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-md-12 center">
                    <div class="clearfix form-actions">
                        <button class="btn btn-purple no-border" type="button" name="btn-query" onclick="query()"
                                id="btn-query">
                            <i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
                            查询
                        </button>
                        &nbsp;&nbsp;&nbsp;
                        <button class="btn btn-grey no-border" type="reset">
                            <i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
                            重置
                        </button>
                    </div>
                </div>
            </div>

		<div id="export" class="row" style="display:none;">
			<div class="col-xs-12">
				<a href="javascript:void(0)" class="btn btn-success btn-small"  id="output2" onclick="loadlist()">导出</a>&nbsp;&nbsp;&nbsp;
			</div><!-- /.col -->
		</div><!-- /.row -->

            <div class="row">
                <div class="col-xs-12">
                    <table id="jquery-table" class="table table-striped table-bordered table-hover">
                    </table>
                </div>
            </div>

        </div>
    </form>
</div>


<%@ include file="/common/common-js.jsp" %>
<script type="text/javascript">
    var loadDom = $('.load_bg,.load_img');
    var jqTable = null;

    function query() {
    	$("#export").show();
        loadDom.show();
        if (jqTable != null) {
            jqTable.fnDraw();
        }
        else {
            loadData();
        }
    }
    
    function loadlist(){
    	var form = document.forms["queryForm"];
    	form.action= ctx + "/weixin/weixin_activity_sumlog_export.action";
    	form.submit();
    }

    var loadData = function () {
        jqTable = $('#jquery-table').dataTable({
            "columnDefs": [
                {
                    "title": '扫码日期',
                    "targets": [0],
                    "data": "date",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '二维码渠道',
                    "targets": [1],
                    "data": "codeChannel",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '优惠码渠道',
                    "targets": [2],
                    "data": "channel",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                
                {
                    "title": '平台',
                    "targets": [3],
                    "data": "platform",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px",
                    "render": function (data) {
                        switch (data) {
                            case -2:
                                return '未知';
                            case -1:
                                return '全平台';
                            case 0:
                                return 'iOS';
                            case 1:
                                return 'Android';
                            case 2:
                                return '其它';
                            default:
                                return '未定义'
                        }
                    }
                },
                {
                    "title": '派券类型',
                    "targets": [4],
                    "data": "type",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px",
                    "render": function (data) {
                        switch (data) {
                            case -1:
                                return '全类型';
                            case 0:
                                return '实物卡';
                            case 1:
                                return '不干胶';
                            default:
                                return '未定义';
                        }
                    }
                },
                {
                    "title": '扫码UV',
                    "targets": [5],
                    "data": "scanUv",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '新关注UV',
                    "targets": [6],
                    "data": "subscribeUv",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '访问链接UV',
                    "targets": [7],
                    "data": "activityUrlUv",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '登记成功UV',
                    "targets": [8],
                    "data": "registerUv",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '领油成功UV',
                    "targets": [9],
                    "data": "activateUv",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                }

            ],
            "sAjaxSource": ctx + "/weixin/weixin_activity_sumlog_record.action",
            "fnServerData": function (url, aoData, fnCallback) {
                var data = $('#queryForm').serializeObject();
                data.aoData = JSON.stringify(aoData);
                $.ajax({
                    "type": "POST",
                    "dataType": 'json',
                    "url": url,
                    "data": data,
                    "success": function (resp) {
                        try {
                            fnCallback(resp);
                        } catch (e) {
                            alert(e.name + ' :' + e.message)
                        }
                        //initListPage();
                    },
                    "error": function (XMLHttpRequest, textStatus) {
                        alert(textStatus);
                        loadDom.hide();
                    },
                    "complete": function () {
                        loadDom.hide();
                    }
                });
            },
            "sScrollXInner": "100%",
            "sScrollY": "100%",
            "aaSorting": [[0, "asc"]]
        });
    };

    jQuery(function ($) {
        $(".date-picker").datepicker({autoclose: true}).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });
        
        $("#codeChannel").combobox();
        $("#channel").combobox();
    });
</script>
</body>
</html>